package cn.sciento.farm.devicemanager.dao.config;


import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;

/**
 * @author wumu
 * @version V1.0
 * @date 7/5/18
 * @time 2:49 PM
 */
public class HistoryPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Long> {

    Logger logger = LoggerFactory.getLogger(getClass());

    private long count = 24*3600*1000L;

    private long  EIGHT_HOURS = 8*3600*1000L;

    private String tableName = "dev_collection_history_";

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {

        long time = shardingValue.getValue().longValue()+EIGHT_HOURS ;
        String dateStr = time/count+"";
        logger.info("查询的历史表名："+dateStr);
        return tableName+dateStr;
    }
}
